/*----------------------------------------------------------------------------

	Copyright (c) 2006, Creator of the Cant Project.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	+ Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

	+ Redistributions in binary form must reproduce the above copyright notice,
	this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.

	+ Neither the name of the Creator of the Cant Project nor the names of its
	contributors may be used to endorse or promote products derived from this
	software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------*/

#ifndef	_UTIL_HPP_
#define	_UTIL_HPP_

#include	<string>
#include	<sstream>

#include	"stringiter.hpp"



/**
	General purpose structure for passing pairs of values.
	
	
	@version	0.1
	@author		<a href="mailto:cant.project@gmail.com">Mikey</a>
*/
template<class X, class Y>
struct Pair
{
	X			left;
	Y			right;
	
	Pair()	: left(), right()
	{}
	
	Pair(const X& a_left, const Y& a_right )	: left(a_left ), right(a_right )
	{}
	
	Pair(const Pair& a_other )	: left(a_other.left ), right(a_other.right )
	{}
	
	Pair&	operator=(const Pair& a_other )
	{
		left			= a_other.left;
		right			= a_other.right;
		
		return	*this;
	}
};



typedef	Pair<std::string,std::string>	StringPair;



/**
	Util class.
	
	Contains utility methods that may be used throughout the application.
	
	
	@version	0.1
	@author		<a href="mailto:cant.project@gmail.com">Mikey</a>
*/
class Util
{
	public:
		/**
			Whitespace.
			
			Used by <code>trim</code>.
		*/
		const static std::string				whitespace;
		
		
		/**
			Empty string.
		
		*/
		const static std::string				empty;
		
		
		/**
			Replaces all instances of one substring with another substring.
	
			@param		a_strOriginal
			@param		a_strFind
			@param		a_strReplace
			@return		string with replacements (if any) performed.
		*/
		static std::string	replace(const std::string& a_strOriginal, const std::string& a_strFind, const std::string& a_strReplace );
		
		
		/**
			Trims whitespace from beginning and end of a string.
			
			@param		a_strOriginal		string to be trimmed.
		*/
		static std::string	trim(const std::string& a_strOriginal );
		
		
		/**
			Splits a string into two parts either side of a separator.
			
			@param		a_strOriginal		string to be split.
			@param		a_strSeparator		separator.
			@return		tuple containing two parts.
		*/
		static StringPair	split(const std::string& a_strOriginal, const std::string& a_strSeparator );
		
		
		/**
			Converts a value to a string.
			
			@param		a_iValue		value to convert.
			@return		converted value.
		*/
		static std::string	toString(int a_iValue );
};

#endif
